﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CSharp1.Properties;

namespace CSharp1
{
    public partial class TestCar : Form
    {
        public TestCar()
        {
            InitializeComponent();
        }
        //创建汽车实例
        Car bmw = null;
        private void button1_Click(object sender, EventArgs e)
        {
            bmw = new Car();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("没有找到要安装的汽车");
                return;
            }
            //创建一个引擎实例
            Engine engine = new Engine();
            //创建一个油箱实例
            OilBox myOil = new OilBox();
            //给引擎设置油箱
            engine.ob = myOil;
            //设置汽车排量
            engine.useOilSeconds = 0.05;
            bmw.carEngine = engine;//设置引擎，赋值
        }

        // 左前胎
        private void button3_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("你倒是给我车呀");
                return;
            }
            //实例化轮胎对象
            Tyre tai = new Tyre();
            tai.brand = "米其林";
            tai.isOk = true;
            bmw.leftFrontTyre = tai;
            pbQianzuo.Visible = true;//显示左前的图片
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("你倒是给我车呀");
                return;
            }
            //实例化轮胎对象
            Tyre tai = new Tyre();
            tai.brand = "米其林";
            tai.isOk = true;
            bmw.rightFrontTyre = tai;
            pbQianyou.Visible = true;//显示右前的图片
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("你倒是给我车呀");
                return;
            }
            //实例化轮胎对象
            Tyre tai = new Tyre();
            tai.brand = "米其林";
            tai.isOk = true;
            bmw.leftBackTyre = tai;
            pbHouzuo.Visible = true;//显示左后的图片
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("你倒是给我车呀");
                return;
            }
            //实例化轮胎对象
            Tyre tai = new Tyre();
            tai.brand = "米其林";
            tai.isOk = true;
            bmw.rightBackTyre = tai;
            pbHouyou.Visible = true;//显示右后的图片
        }

        private void pbHouzuo_Click(object sender, EventArgs e)
        {
            if (bmw == null)
            {
                MessageBox.Show("车都没有这么卸");
                return;
            }
            bmw.leftBackTyre = null;//直接设置为null
            pbHouzuo.Visible = false;//隐藏图片
        }

        /// <summary>
        /// 图标变成启动
        /// </summary>
        public void SetQidong()
        {
            pbStatus.Image = Resources.circle_start;
        }
        /// <summary>
        /// 图标变成停止
        /// </summary>
        public void SetTingzhi()
        {
            pbStatus.Image = Resources.circle_stop;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblYouliang.Text = bmw.carEngine.ob.Value.ToString();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (bmw != null)
            {
                bmw.Fire();
                if (bmw.carEngine.isStart)
                {//是否启动成功
                    timer1.Enabled = true;//启动油量探测器
                    timerCarRun.Enabled = true;//汽车开始运行
                }
            }
            else
            {
                MessageBox.Show("没有车");
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            bmw.carEngine.ob.Value = 1000;
        }

        private void timerCarRun_Tick(object sender, EventArgs e)
        {
            bmw.Run();
        }
    }
}
